package com.onesports.intelligent.k12.polarlight.controller.common;
import com.onesports.framework.kit.common.valid.Json;
import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.common.IdDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.sys.DictDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.sys.DictSelectDTO;
import com.onesports.intelligent.k12.polarlight.domain.entity.sys.Dict;
import com.onesports.intelligent.k12.polarlight.service.sys.SysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chenrl
 **/
@Api(tags = "运营端-系统管理-字典管理")
@RestController
@RequiredArgsConstructor
@RequestMapping(ApiPathConstants.SYS_DICT)
public class SysDictController {

    private final SysDictService sysDictService;

    @ApiOperation("添加字典信息")
    @PostMapping("/add")
    public ResponseEntity<String> add(@Json @RequestBody DictDTO dictDTO) {
        this.sysDictService.add(dictDTO);
        return ResultUtil.success("添加成功!");
    }
    @ApiOperation("修改字典信息")
    @PostMapping("/update")
    public ResponseEntity<String> update(@Json @RequestBody DictDTO dictDTO) {
        this.sysDictService.update(dictDTO);
        return ResultUtil.success("修改成功!");
    }
    @ApiOperation("删除字典信息")
    @PostMapping("/delete")
    public ResponseEntity<String> delete(@Json @RequestBody IdDTO idDTO) {
        this.sysDictService.delete(idDTO);
        return ResultUtil.success("删除成功!");
    }
    @ApiOperation("条件查询字典信息")
    @GetMapping("/select")
    public ResponseEntity<List<Dict>> select(DictSelectDTO dictSelectDTO) {
        return ResultUtil.success(sysDictService.select(dictSelectDTO));
    }

    @ApiOperation("根据父id查询字典信息")
    @GetMapping("/select-pid")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "父id", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseEntity<List<Dict>> selectById(String parentId) {
        return ResultUtil.success(sysDictService.selectById(parentId));
    }
}













